home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / control / lyap.m < prev    next >
Text File  |  1996-07-15  |  2KB  |  108 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Usage: x = lyap (a, b {,c})
  21. ##
  22. ## If (a, b, c) are specified, then lyap returns the solution of the
  23. ## Sylvester equation
  24. ##
  25. ##   a x + x b + c = 0
  26. ##
  27. ## If only (a, b) are specified, then lyap returns the solution of the
  28. ## Lyapunov equation
  29. ##
  30. ##   a' x + x a + b = 0
  31. ##
  32. ## If b is not square, then lyap returns the solution of either
  33. ##
  34. ##   a' x + x a + b' b = 0
  35. ##
  36. ## or
  37. ##
  38. ##   a x + x a' + b b' = 0
  39. ##
  40. ## whichever is appropriate.
  41. ##
  42. ## Solves by using the Bartels-Stewart algorithm (1972).
  43.  
  44. ## Author: A. S. Hodel <scotte@eng.auburn.edu>
  45. ## Created: August 1993
  46. ## Adapted-By: jwe
  47.  
  48. function x = lyap (a, b, c)
  49.  
  50.   if (nargin != 3 && nargin != 2)
  51.     usage ("lyap (a, b {,c})");
  52.   endif
  53.  
  54.   if ((n = is_square(a)) == 0)
  55.     error ("lyap: a is not square");
  56.   endif
  57.  
  58.   if (nargin == 2)
  59.  
  60.     ## Transform Lyapunov equation to Sylvester equation form.
  61.  
  62.     if ((m = is_square (b)) == 0)
  63.       if ((m = rows (b)) == n)
  64.  
  65.     ## solve a x + x a' + b b' = 0
  66.  
  67.     b = b * b';
  68.     a = a';
  69.       else
  70.  
  71.     ## Try to solve a'x + x a + b' b = 0.
  72.  
  73.     m = columns (b);
  74.     b = b' * b;
  75.       endif
  76.  
  77.       if (m != n)
  78.     error ("lyap: a, b not conformably dimensioned");
  79.       endif
  80.     endif
  81.  
  82.     ## Set up Sylvester equation.
  83.  
  84.     c = b;
  85.     b = a;
  86.     a = b';
  87.  
  88.   else
  89.  
  90.     ## Check dimensions.
  91.  
  92.     if ((m = is_square (b)) == 0)
  93.       error ("lyap: b must be square in a sylvester equation");
  94.     endif
  95.  
  96.     [n1, m1] = size(c);
  97.  
  98.     if (n != n1 || m != m1)
  99.       error("lyap: a,b,c not conformably dimensioned");
  100.     endif
  101.   endif
  102.  
  103.   ## Call octave built-in function.
  104.  
  105.   x = syl (a, b, c);
  106.  
  107. endfunction
  108.